'use strict';

//模拟加载新闻
function topic() {
  $.server({ categoryId: 28, pageSize: 6, pageNum: 1 }, '/website/v1/queryCategoryContent').then(function (res) {
    console.log(res, "行业新闻");
    var obj = res.result.data;
    var html = '',
        length = obj.length > 6 ? 6 : obj.length;
    for (var i = 0; i < length; i++) {
      //   if (i == 0) {
      //     html += ` <a onclick="goLessonDetail(${obj[i].contentId},'院校','课题展示')">
      //     <div class="new-title-box col-md-12 col-sm-12 col-xs-12">
      //         <div class="new-title mouseTitle">${obj[i].title}</div>
      //         <div class="new-content-box">
      //             <img class="new-img img-responsive" src="${obj[i].poster}"></img>
      //             <div class="new-word mouseMethod">
      //             ${obj[i].description}
      //             </div>
      //         </div>
      //     </div>
      // </a>`;
      //   } else {
      html += '<a onclick="goLessonDetail(' + obj[i].contentId + ',\'\u9662\u6821\',\'\u8BFE\u9898\u5C55\u793A\')"><div class="topic-box title-box col-md-12 col-sm-12 col-xs-12">\n        <div class="flex-box">\n        <div class="around"></div>\n        <div class="topic-title">' + obj[i].title + '</div>\n        </div>\n        <div class="more">' + obj[i].createTime.substring(5, 10) + '</div>\n        </div></div>';
    }
    // }
    $("#topicContent").html(html);
  });
}
//模拟加载学校
// function colleges(){
//   $.server({ categoryId: 33, pageSize: 6, pageNum: 1 }, '/website/v1/queryCategoryContent').then((res) => {
//     console.log(res, "学校")
//     let obj = res.result.data
//     let html = '', length = obj.length > 8 ? 8 : obj.length;
//     for (let i = 0; i < length; i++) {
//       html += `<div class="coolleges-w-box col-md-3 col-sm-3 col-xs-3">
//       <img src=${obj[i].poster} class="coolleges-img img-responsive" alt="">
//       <div class="coolleges-name">${obj[i].title}</div>
//   </div>`
//     }
//     $("#colleges").html(html);
//   })
// }
//模拟加载学校
function colleges() {
  var obj = [{ title: '中央财经大学', img: 'images/coolleges/coolleges-1.png', id: '344' }, { title: '北京大学', img: 'images/coolleges/coolleges-2.png', id: '344' }, { title: '天津财经大学', img: 'images/coolleges/coolleges-3.png', id: '344' }, { title: '东北财经大学', img: 'images/coolleges/coolleges-4.png', id: '344' }, { title: '中国人民大学', img: 'images/coolleges/coolleges-5.png', id: '344' }, { title: '复旦大学', img: 'images/coolleges/coolleges-6.png', id: '344' }, { title: '清华大学', img: 'images/coolleges/coolleges-7.png', id: '344' }, { title: '同济大学', img: 'images/coolleges/coolleges-8.png', id: '344' }];
  var html = '',
      length = obj.length > 10 ? 10 : obj.length;

  for (var i = 0; i < length; i++) {
    html += '<div class="coolleges-w-box col-md-3 col-sm-3 col-xs-3">\n    <img src=' + obj[i].img + ' class="coolleges-img img-responsive" alt="">\n    <div class="coolleges-name">' + obj[i].title + '</div>\n</div>';
  }
  $("#colleges").html(html);
}
//模拟加载研究成果
function researchFindings() {
  $.server({ categoryId: 29, pageSize: 6, pageNum: 1 }, '/website/v1/queryCategoryContent').then(function (res) {
    console.log(res, "专题报告");
    var obj = res.result.data;
    var html = '',
        length = obj.length > 6 ? 6 : obj.length;
    for (var i = 0; i < length; i++) {
      //   if (i == 0) {
      //     html += ` <a onclick="goLessonDetail(${obj[i].contentId},'院校','研究成果')">
      //     <div class="new-title-box col-md-12 col-sm-12 col-xs-12">
      //         <div class="new-title mouseTitle">${obj[i].title}</div>
      //         <div class="new-content-box">
      //             <img class="new-img img-responsive" src="${obj[i].poster}"></img>
      //             <div class="new-word mouseMethod">
      //             ${obj[i].description}
      //             </div>
      //         </div>
      //     </div>
      // </a>`;
      //   } else {
      html += '<a onclick="goLessonDetail(' + obj[i].contentId + ',\'\u9662\u6821\',\'\u7814\u7A76\u6210\u679C\')"><div class="topic-box title-box col-md-12 col-sm-12 col-xs-12">\n      <div class="flex-box">\n      <div class="around"></div>\n      <div class="topic-title">' + obj[i].title + '</div>\n      </div>\n      <div class="more">' + obj[i].createTime.substring(5, 10) + '</div>\n      </div></div>';
    }
    // }
    $("#researchFindings").html(html);
  });
}
// 页面顶部大图数据(待定)
function posterImg() {
  $.server({ location: 6 }, '/website/v1/getPoster').then(function (res) {
    console.log(res, "页面顶部大图数据");
    $('#bannerImg').attr("src", res.result.data[0].url);
  });
}
/**
 * 跳转到文章详情
 */
function goLessonDetail(id, word, childTitle) {
  location.href = 'industryDetail.html?id=' + id + '&word=' + word + '&childTitle=' + childTitle;
}
function more() {
  var id = 28;
  location.href = 'articleList.html?id=' + id + '&type=10';
}
function more1() {
  var id = 29;
  location.href = 'articleList.html?id=' + id + '&type=11';
}
/**
 * 页面初始化时加载 window.onload
 */
$(function () {
  //调用server加载首页新闻
  posterImg();
  topic();
  colleges();
  researchFindings();

  $("#topicContent .topic-title").click(function (e) {
    var index = e.currentTarget.dataset.index;
    console.log(e);
    if (index == 1) {} else if (index == 2) {} else if (index == 3) {}
  });

  $("#researchFindings .topic-title").click(function (e) {
    var index = e.currentTarget.dataset.index;
    if (index == 1) {} else if (index == 2) {} else if (index == 3) {}
  });
});